<include file="_header" />
<script>
function getChecked() {
    var ids = new Array();
    $.each($('table input:checked'), function(i, n){
        ids.push( $(n).val() );
    });
    return ids;
}

function checkon(o){
    if( o.checked == true ){
        $(o).parents('tr').addClass('bg_on') ;
    }else{
        $(o).parents('tr').removeClass('bg_on') ;
    }
}

function checkAll(o){
    if( o.checked == true ){
        $('input[name="checkbox"]').attr('checked','true');
        $('tr[overstyle="on"]').addClass("bg_on");
    }else{
        $('input[name="checkbox"]').removeAttr('checked');
        $('tr[overstyle="on"]').removeClass("bg_on");
    }
}

//搜索用户
var isSearchHidden = <neq name="isSearch" value="1">1<else/>0</neq>;
function searchObject() {
    if(isSearchHidden == 1) {
        $("#searchObject_div").slideDown("fast");
        $(".searchObject_action").html("搜索完毕");
        isSearchHidden = 0;
    }else {
        $("#searchObject_div").slideUp("fast");
        $(".searchObject_action").html("搜索{$ts['app']['app_alias']}");
        isSearchHidden = 1;
    }
}

var ctrl = function(){
}
ctrl.prototype = {
	del:function(id){
		var id = id ? id : getChecked();
		id = id.toString();
		if(id=='' || id==0) return ;
		if( confirm("是否删除{$ts['app']['app_alias']}？") ){
		  $.post( '__URL__&act=delete',{id:id},function(text ){
			  if( text == 1 ){
				  ui.success( "删除多份{$ts['app']['app_alias']}成功" );
				  var id_list = id.split( ',' );   
				  for (var j=0 ; j< id_list.length ; j++   ){
					  $('#list_'+id_list[j]).remove(); 
				  }
			  }else if( text == 2 ){
				  ui.success( "删除成功" );
				  $('#list_'+id).remove();
			  }else{
				  ui.error( "删除失败" );
			  }
		  });
		}
	},
	forbid:function(id){
		var id = id ? id : getChecked();
		id = id.toString();
		if(id=='' || id==0) return ;
	    if( confirm( "是否禁用{$ts['app']['app_alias']}" ) ){
	      $.post('__URL__&act=forbid',{id:id},function( text ){
			 if( text == 1 ){
				 ui.success( "禁用多份{$ts['app']['app_alias']}成功" );
				  var id_list = id.split( ',' );   
				  for (var j=0 ; j< id_list.length ; j++   ){
					  $('#status'+id_list[j]).html('{:getStatus(0)}');
					  $('#button'+id_list[j]).html('<a href="javascript:void(0);" onclick="c.resume('+id_list[j]+')">启用</a> ');
				  }
			 }else if( text == 2 ){
				 ui.success( "禁用成功" );
				 $('#status'+id).html('{:getStatus(0)}');
				 $('#button'+id).html('<a href="javascript:void(0);" onclick="c.resume('+id+')">启用</a> ');
			 }else{
			 	 ui.error( "禁用失败或已经禁用" );
		   	 }
	      });
	    }
	},
	resume:function(id){
		var id = id ? id : getChecked();
		id = id.toString();
		if(id=='' || id==0) return ;
	    if( confirm( "是否启用{$ts['app']['app_alias']}" ) ){
	      $.post('__URL__&act=resume',{id:id},function( text ){
			 if( text == 1 ){
				 ui.success( "启用多份{$ts['app']['app_alias']}成功" );
				  var id_list = id.split( ',' );   
				  for (var j=0 ; j< id_list.length ; j++   ){
					  $('#status'+id_list[j]).html('{:getStatus(1)}');
					  $('#button'+id_list[j]).html('<a href="javascript:void(0);" onclick="c.forbid('+id_list[j]+')">禁用</a> ');
				  }
			 }else if( text == 2 ){
				 ui.success( "启用成功" );
				 $('#status'+id).html('{:getStatus(1)}');
				 $('#button'+id).html('<a href="javascript:void(0);" onclick="c.forbid('+id+')">禁用</a> ');
			 }else{
			 	 ui.error( "启用失败或已非禁用" );
		   	 }
	      });
	    }
	},
	edit_tab:function(action,id){
		var title = action+"{$ts['app']['app_alias']}";
		ui.box.load('__URL__&act=edit_gift_tab&id='+id,{title:title+'信息'});
	}
}
var c = null;
</script>
<div class="so_main">
  <include file="_tab" /> 

    <div id="searchObject_div" <neq name="isSearch" value="1">style="display:none;"</neq>>
    <div class="page_tit">搜索{$ts['app']['app_alias']} [ <a href="javascript:void(0);" onclick="searchObject();">隐藏</a> ]</div>
    <div class="form2">
    <form action="__URL__&act=giftlist" method="post">
    <input type="hidden" name="isSearch" value="1"/>
        <php>if($isSearch != '1') $uid = '';</php>
        <dl class="lineD">
          <dt>{$ts['app']['app_alias']}ID：</dt>
          <dd>
            <input name="id" class="txt" value="{$userId}">
          </dd>
        </dl>
	    <dl class="lineD">
          <dt>{$ts['app']['app_alias']}名称：</dt>
          <dd>
            <input name="name" class="txt" value="{$name}"/><span> 支持模糊查询。</span>
          </dd>
        </dl>
	    <dl class="lineD">
          <dt>所属类别：</dt>
          <dd>
            <select name="categoryId">
              <option value="">所有类别</option>
           	  <php>foreach($categorysInfo as $k=>$v){
				   if($categoryId==$k) { </php>
					   <option value="{$k}" selected="selected">{$v}</option>
			  <php>}else{</php>	
					   <option value="{$k}">{$v}</option>
			  <php>}}</php>
			</select>
          </dd>
        </dl>
	    <dl class="lineD">
          <dt>启用状态：</dt>
          <dd>
            <select name="status">
              <option value="">所有</option>
              <option value="1" <eq name="status" value="1">selected</eq>>启用</option>
              <option value="0" <eq name="status" value="0">selected</eq>>禁用</option>
			</select>
          </dd>
        </dl>
	    <dl class="lineD">
          <dt>结果排序：</dt>
          <dd>
            <select name="order">
			  <option value = "desc" <eq name="order" value="desc">selected</eq>>降序排列，新的在前</option>
			  <option value = "asc" <eq name="order" value="asc">selected</eq>>升序排列，旧的在前</option>
			</select>
          </dd>
        </dl>
        <div class="page_btm">
	      <input type="submit" class="btn_b" value="确定" />
	    </div>
    </form>
    </div>
    </div>    
    <div class="Toolbar_inbox">
        <div class="page right">{$list.html}</div>
        <a href="javascript:void(0);" class="btn_a" onclick="searchObject();">
            <span class="searchObject_action"><neq name="isSearch" value="1">搜索{$ts['app']['app_alias']}<else/>搜索完毕</neq></span>
        </a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.edit_tab('添加')"><span>添加{$ts['app']['app_alias']}</span></a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.del()"><span>删除{$ts['app']['app_alias']}</span></a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.resume()"><span>启用{$ts['app']['app_alias']}</span></a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.forbid()"><span>禁用{$ts['app']['app_alias']}</span></a>
    </div>

	<div class="list">
        <table id="object_list" width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
		    <th style="width:30px;">
		      <input type="checkbox" id="checkbox_handle" onclick="checkAll(this)" value="0">
		      <label for="checkbox"></label>
		    </th>
            <th>ID</th>
            <th>预览</th>
            <th>名称</th>
            <th>所属</th>
            <th>价格</th>
            <th>数量</th>
            <th>时间</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
          <volist name="list.data" id="vo">
          <tr id="list_{$vo.id}">          
            <td><input type="checkbox" name="checkbox" id="checkbox2" onclick="checkon(this)" value="{$vo.id}"></td>
            <td>{$vo.id}</td>
            <td height="70"><img src="{$vo.img|realityImageURL}" /></td>
            <td>{$vo.name}</td>
            <td>{$categorysInfo[$vo['categoryId']]}</td>
            <td>{$vo.price}</td>
            <td>{$vo.num}</td>
            <td>{$vo.cTime|date="Y-m-d H:i:s",###}</td>
            <td><span id="status{$vo['id']}" >{$vo.status|getStatus}</span></td>
            <td>
            	<span id="button{$vo['id']}" >
                <php>if($vo['status']==0){</php>
                    <a href="javascript:void(0);" onclick="c.resume('{$vo.id}')">启用</a>
                <php>}else{</php>
                    <a href="javascript:void(0);" onclick="c.forbid({$vo.id})">禁用</a>
                <php>}</php>
                </span>
                <a href="javascript:void(0);" onclick="c.edit_tab('编辑','{$vo.id}')">编辑</a>
                <a href="javascript:void(0);" onclick="c.del('{$vo.id}')">删除</a>
             </td>
          </tr>
          </volist>
        </table>
    </div>
    
    <div class="Toolbar_inbox">
        <div class="page right">{$list.html}</div>
        <a href="javascript:void(0);" class="btn_a" onclick="searchObject();">
            <span class="searchObject_action"><neq name="isSearch" value="1">搜索{$ts['app']['app_alias']}<else/>搜索完毕</neq></span>
        </a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.edit_tab('添加')"><span>添加{$ts['app']['app_alias']}</span></a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.del()"><span>删除{$ts['app']['app_alias']}</span></a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.resume()"><span>启用{$ts['app']['app_alias']}</span></a>
        <a href="javascript:void(0);" class="btn_a" onclick="c.forbid()"><span>禁用{$ts['app']['app_alias']}</span></a>
    </div>
</div>
<script type="text/javascript">
var c = new ctrl();
</script>
<include file="_footer" />